<?php
class comment extends CI_Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->load->model('comment_model');
        $this->load->library('pagination');
        $this->load->helper('url');
    }
    public function index(){
        $data['title'] = "List Comment";
        $data['path'] = "comment/list";

        $config['base_url'] = base_url().'admincp/comment/index'; //url page cần PT
        $config['total_rows'] = $this->comment_model->totalComment(); //Total record
        $config['uri_segment'] = 4;
        //css pag
        $config['full_tag_open'] = '<ul class="tsc_pagination tsc_paginationA tsc_paginationA01">';
        $config['full_tag_close'] = '</ul>';
        $config['prev_link'] = '&lt;';
        $config['prev_tag_open'] = '<li>';
        $config['prev_tag_close'] = '</li>';
        $config['next_link'] = '&gt;';
        $config['next_tag_open'] = '<li>';
        $config['next_tag_close'] = '</li>';
        $config['cur_tag_open'] = '<li class="current"><a href="#">';
        $config['cur_tag_close'] = '</a></li>';
        $config['num_tag_open'] = '<li>';
        $config['num_tag_close'] = '</li>';
        $config['first_tag_open'] = '<li>';
        $config['first_tag_close'] = '</li>';
        $config['last_tag_open'] = '<li>';
        $config['last_tag_close'] = '</li>';
        $config['first_link'] = '&lt;&lt;';
        $config['last_link'] = '&gt;&gt;';
        //end
        $config['per_page'] = 3;  // Số record hiển thị trên 1 trang
        $this->pagination->initialize($config);
        $start = $this->uri->segment(4);
        // End pagination
        $data['comment'] = $this->comment_model->listComment($config['per_page'],$start);
        $data['nameproduct'] = $this->comment_model->nameProduct();
        $this->load->view('dashboard/index',$data);
    }
    public function checkShow(){
        $data['title'] = "List Comment";
        $data['path'] = "comment/list";

        $config['base_url'] = base_url().'admincp/comment/index'; //url page cần PT
        $config['total_rows'] = $this->comment_model->totalComment(); //Total record
        $config['uri_segment'] = 4;
        //css pag
        $config['full_tag_open'] = '<ul class="tsc_pagination tsc_paginationA tsc_paginationA01">';
        $config['full_tag_close'] = '</ul>';
        $config['prev_link'] = '&lt;';
        $config['prev_tag_open'] = '<li>';
        $config['prev_tag_close'] = '</li>';
        $config['next_link'] = '&gt;';
        $config['next_tag_open'] = '<li>';
        $config['next_tag_close'] = '</li>';
        $config['cur_tag_open'] = '<li class="current"><a href="#">';
        $config['cur_tag_close'] = '</a></li>';
        $config['num_tag_open'] = '<li>';
        $config['num_tag_close'] = '</li>';
        $config['first_tag_open'] = '<li>';
        $config['first_tag_close'] = '</li>';
        $config['last_tag_open'] = '<li>';
        $config['last_tag_close'] = '</li>';
        $config['first_link'] = '&lt;&lt;';
        $config['last_link'] = '&gt;&gt;';
        //end
        $config['per_page'] = 3;  // Số record hiển thị trên 1 trang
        $this->pagination->initialize($config);
        $start = $this->uri->segment(4);
        // End pagination
        $data['nameproduct'] = $this->comment_model->nameProduct();
        $data['comment'] = $this->comment_model->listComment($config['per_page'], $this->uri->segment(4));
        if ($this->input->post('show') != NULL) {
            if (isset($_POST['check'])) {
                foreach ($_POST['check'] as $key => $value) {
                    $this->comment_model->updateShow($value);
                }
                redirect(base_url() . "admincp/comment");
            } else {
                $this->load->view('dashboard/index',$data);
            }
        } elseif ($this->input->post('delete') != NULL) {
            if (isset($_POST['check'])) {
                foreach ($_POST['check'] as $key => $value) {
                    $this->comment_model->delete($value);
                }
                redirect(base_url() . "admincp/comment");
            } else {
                $this->load->view('dashboard/index',$data);
            }
        } else {
            $this->load->view('dashboard/index',$data);
        }
    }
    public function deleteComment(){
        $id = $this->uri->segment(4);
        $this->comment_model->delete($id);
        redirect(base_url() . "admincp/comment");
        exit();
    }

    public function detail()
    {
        $id = $this->uri->segment(4);
        $data['title'] = "Chi tiết";
        $data['path'] = "comment/detail";
        $data['info'] = $this->comment_model->getdata($id);
        $data['nameproduct'] = $this->comment_model->nameProduct();
        $this->load->view("dashboard/index",$data);

    }
}